<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="relname" placeholder="请输入姓名" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">微信号</label>
                            <div class="layui-input-inline">
                                <input type="text" name="reCode" placeholder="请输入微信号" autocomplete="off"
                                       class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">添加时间</label>
                            <div class="layui-input-inline">
                                <input type="text" name="classify" id="classify" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit
                                    lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索
                            </button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <!--                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加</button>-->
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除</button>
            </div>
        </script>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <!--            <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>-->
            {{# if(d.state == 0){ }}
            <a class="layui-btn layui-btn-xs layui-btn-warm data-count-delete" lay-event="openState">通过</a>
            <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="openError">拒绝</a>
            {{# }else if(d.state == 1){ }}
            审核通过
            {{# }else{ }}
            审核拒绝
            {{# } }}
        </script>

    </div>
</div>

<script>
    layui.use(['form', 'table', 'laydate'], function () {
        let $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;

        laydate.render({
            elem: '#classify'
            , type: 'datetime'
            , range: '~'
            , value: "{$start_time} ~ {$end_time}"
        });
        let tableIns = table.render({
            elem: '#currentTableId',
            url: "{:url('index')}",
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',  //事件名，用于 toolbar 事件中使用
                icon: 'layui-icon-search'  //图标类名
            }],
            cols: [[
                {type: "checkbox", width: 50},
                {field: 'id', width: 80, title: 'ID', sort: true},
                {field: 'relname', title: '提现姓名'},
                {field: 'reCode', title: '微信号'},
                {field: 'money', title: '金额'},
                {field: 'create_time', title: '申请时间'},
                {title: '操作', minWidth: 150, toolbar: '#currentTableBar', align: "center"}
            ]],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
            , response: {
                statusName: 'code' //规定数据状态的字段名称，默认：code
                , statusCode: 1 //规定成功的状态码，默认：0
                , msgName: 'msg' //规定状态信息的字段名称，默认：msg
                , countName: 'count' //规定数据总数的字段名称，默认：count
                , dataName: 'data' //规定数据列表的字段名称，默认：data
            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            tableIns.reload({
                where: data.field
                , page: {
                    curr: 1 //重新从第 1 页开始
                }
            })

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                hadmin.add("添加", "{:url('add')}")
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('currentTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            } else if (obj.event === 'LAYTABLE_TIPS') {
                $(".table-search-fieldset").slideToggle()
            }
        });

        //监听表格复选框选择
        table.on('checkbox(currentTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/edit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            } else if (obj.event === 'openState') {
                layer.confirm('确定审核通过吗？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    hadmin.http("{:url('openState')}", {
                        id: data.id
                    }).then(res => {
                        if (res.code == "{$result.normal}") {
                            tableIns.reload()
                        }
                    })
                });
            } else if (obj.event === 'openError') {
                layer.prompt({title: '请输入拒绝原因', formType: 2}, function (pass, index) {
                    layer.close(index);
                    hadmin.http("{:url('openError')}", {
                        id: data.id,
                        text: pass
                    }).then(res => {
                        if (res.code == "{$result.normal}") {
                            tableIns.reload()
                        }
                    })
                });
            }

        });

    });
</script>
